<template>
  <div>
    <el-card>
      <p>修改题目</p>
      <el-form ref="ruleForm" :model="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="上传者" prop="title">
          <el-input v-model="ruleForm.uploder" disabled style="width:220px" />
        </el-form-item>
        <el-form-item label="题目分类" prop="cate">
          <el-select v-model="ruleForm.cate_id" :placeholder="ruleForm.cata_o.cateName">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.cateName"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="题目内容" prop="title">
          <el-input v-model="ruleForm.title" />
        </el-form-item>
        <el-form-item label="题目答案" prop="answer">
          <quill-editor
            ref="richAnalysis"
            v-model="ruleForm.answer"
            style="color:#333"
          />
        </el-form-item>
        <el-form-item class="tij">
          <el-button type="primary" @click="upd">立即修改</el-button>
          <el-button @click="fan">返回</el-button>
        </el-form-item>
      </el-form>

    </el-card>
  </div>
</template>

<script>
export default {
  components: {},
  props: {},
  data() {
    return {
      ruleForm: {},
      options: []
    }
  },
  computed: {},
  watch: {},
  async created() {
    this.getlei()
    // console.log(this.$route.query)
    this.ruleForm = JSON.parse(this.$route.query.row)
    // console.log(JSON.parse(this.$route.params.row),'213312321');
    // var res=await this.http.get('/cateall')
    // if(res.data.code==200){
    //     this.options=res.data.data
    // }
    // console.log(this.options)
    // this.ruleForm.uploader=sessionStorage.getItem("user")
  },
  mounted() {},
  methods: {
    fan() {
      this.$router.go(-1)
    },
    async upd() {
      var res = await this.http.put(`/knowledge/dques/`, this.ruleForm)
      console.log(res)
      // var res=await this.http.put(`/api/dques/${this.ruleForm._id}`,{
      //     title:this.ruleForm.title,
      //     answer:this.ruleForm.answer,
      //     uploader:this.ruleForm.uploader,
      //     cate:this.ruleForm.cate._id
      // })
      if (res.data.code == 200) {
        this.$message.success('修改题目成功')
        this.$router.push('/question')
      } else {
        this.$message.error('修改题目失败')
      }
    },
    async getlei() {
      var res = await this.http.get('/knowledge/lei/')

      console.log(res, 'lei')
      //   var res=await this.http.get('/cateall')
      if (res.data.code == 200) {
        // this.tableData = res.data.data1
        this.options = res.data.data
        // this.queryInfo.t=res.data.count
      }
    }
  }
}
</script>
<style scoped>
</style>
